The build and deploy Tasks
Let's learn about the build and deploy Tasks using Tekton Pipelines directly through the manifest.
We'll cover the following
The build Task#
Let’s start with the build Task. This Task will take in inputs (like the Git repository URL) and build and publish an image. We’ve already created a file named task-build.yaml. First, we need to run the command mentioned in taskBuild.sh.
Note: Click the “Run” button under the widget shown below and enter the commands in the terminal.
To run all the commands written in a
.shfile, just type./file-name.shin the terminal.
/
The Task definition, as mentioned in task-build.yaml, defines a Task with the name build. The Task takes multiple inputs (such as the Git repository URL) and outputs a container image. These inputs and outputs are referred to as resources in Tekton. The params field defines input parameters for the Task. For example, repo-URL represents the Git repository to clone. A Task can emit string results, defined in the results field, whose values can be viewed by users or passed to other Tasks in a pipeline. The published image is returned for the build Task we created.
The Task has the following two steps:
-
The git-clone step uses the alpine/git image to clone the repository. It reads the repository URL from the ingested parameter using
$(params.repo-url). -
The build-image step uses Buildah to build and publish the image. It reads the Dockerfile and source code from the same volume as the git-clone Task stored in the cloned repository. The Task creates an
emptyDirPersistent Volume that caches data across multiple Steps. This is specified using thevolumesfield. After the image is published, the image path is emitted as the Task’s result usingecho -n "$(params.image)" | tee $(results.image.path).
Let’s test it and make sure the Task works! We’ll need a TaskRun for this. A TaskRun allows us to instantiate and execute a Task.
Let’s create a TaskRun from the Tekton Dashboard.
-
Step 1: Open the Tekton Dashboard using the domain we assigned to it
: http://dashboard-tekton.<EXTERNAL_IP>.sslip.io. Note: Here’s the command that you can use to check the external IP of the cluster:
kubectl get svc -n kourier-system -o yaml | grep ip: -
Step 2: Click the “TaskRuns” menu on the sidebar. We should be redirected to the TaskRuns page.
-
Step 3: Click the “Create” button. This should take us to the Create TaskRun page.
-
Step 4: On the Create TaskRun page, select the “default” namespace from the dropdown and select “build” on the Task field.
We should see the fields to enter values for the task parameters. Most of them should be filled with the default values specified in the Task.
-
Step 5: Enter
https://github.com/pmbanugo/kn-nodejs-svcfor the repo-URL field. -
Step 6: Enter a value for the image page. The image field’s value should be in the following format: server/namespace/repository:tag.
Note: Your image will be pushed to the path specified above.
- Step 7: For the ServiceAccount field, select “tekton”, which is the ServiceAccount we created earlier.
That’s all that’s needed to run the Task.
- Step 8: Scroll to the top and click the “Create” button. We’ll be redirected to the TaskRuns page while the Task is initiated and executed.
We should see a green checkmark after the Task is executed and finishes successfully.
- Step 9: We can click the “TaskRun” name to see how the Task was executed.
Note: We should see something similar to what is shown in the figure. We can click around to see more logs or check our registry to be sure the image was published.
See the slides below to visualize the steps.
1 of 9
2 of 9
3 of 9
4 of 9
5 of 9
6 of 9
7 of 9
8 of 9
9 of 9
The deploy Task#
The next step in creating the pipeline is to define a Task to deploy a Knative service. To do so, a new manifest is created in the task-deploy.yaml file. The deploy Task is much leaner when compared to the build Task. It uses the latest kn CLI image to deploy a service using the kn service apply command.
The apply command will create a new service if none exists. Otherwise, it’ll update the service.
Apply the newly created manifest by running the following command:
kubectl apply -f task-deploy.yaml
/
Let’s run the deploy Task to make sure it’s working.
-
Step 1: Open the Tekton Dashboard and go to the TaskRuns page:
http://dashboard-tekton.<EXTERNAL_IP>.sslip.io. -
Step 2: Click the “Create” button to create a TaskRun.
-
Step 3: On the Create TaskRun page, select the “default” namespace from the “Namespace” dropdown and, on the Task field, select “deploy”.
We should see fields to enter values for the task’s parameters. Most of them should be filled with the default values specified in the task.
-
Step 4: Enter “tekton-demo” for the service field.
-
Step 5: Use the image path generated from the
buildTaskRun. -
Step 6: Select “tekton” for the ServiceAccount field.
-
Step 7: Click the “Create” button at the top right corner of the page.
We should be redirected to the TaskRuns page. We’ll see a green checkmark after the task is executed and finishes successfully.
After it’s completed, the service should be deployed and available on http://tekton-demo.default.<YOUR_IP>.sslip.io.
See the slides below to visualize the steps.
1 of 7
2 of 7
3 of 7
4 of 7
5 of 7
6 of 7
7 of 7
Configure the Container Registry Credential and ServiceAccount
Create the Tekton Pipeline